package com.example.baseexercises.Redis;

/**
 * @author: 辛之所想
 * @create: 2025-11-15 20:43
 * @description:
 **/
import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("/redisSortedSet")
@Tag(name = "RedisSortedSet",description = "RedisSortedSet操作")
public class RedisSortedSet {
    
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    
    @GetMapping("/redisSortedSetTest")
    @Operation(summary = "RedisSortedSet测试") 
    public String redisSortedSetTest() {
        set("redisSortedSet", "redisSortedSet");
        return JSON.toJSONString(get("redisSortedSet",0,1));
    }
    public void set(String key, String value) {
        stringRedisTemplate.opsForZSet().add(key,value,1);
    }
    
    public Set get(String key, int start, int end) {
        return stringRedisTemplate.opsForZSet().range(key, start, end);
    }
}
